<template>
	<view class="">
		<view class="getmyredgift" style="background: rgba(244, 239, 230, 1);overflow-x: hidden;overflow-y:hidden ;">
			<view class="" style="background:#fafafa;background-size: 150% 150%;width: 100%;height: 100%;z-index: 999;position: relative;">
				<view class="title" style="background :url(../../static/image/reddetail.png) no-repeat;background-size :100% 100%;		width: 120%;height:430upx;margin-left: -9.5%;">
					<view class="header">
						<view class="left">
							<image src="../../static/image/hongbaoback.png" mode="" @tap="back" style="width: 66upx;height: 66upx;margin-top: 120upx;margin-left: 120upx;"></image>
						</view>
					</view>
				</view>
				<div class="resAllopen">
					<div class="openname">{{name}}</div>
					<div class="openremake">{{remaketext}}</div>
					<div class="allamount">
						<span class="amountnum">{{amounttop}}</span>
						<span class="assetname">{{assetnametop}}</span>
					</div>
					<div class="hx"></div>
					<div class="redlist">
						<div class="redtext">领取{{status}}/{{alllist.length}}个</div>
						<div class="redkuang">
							<div class="redListAll" v-for="(item,index) in redlist">
								<div class="modular">
									<!-- <image src="../../static/image/1024.png" style="height: 87upx;widht:87upx;margin-top: 10upx;margin-right: 10upx;" /> -->
									<image v-if="item.assetid==0"  src="../../static/image/icon_detail.png" style="height: 87upx;widht:87upx;margin-top: 10upx;margin-right: 10upx;"></image>
									<image  v-else src="../../static/image/greylogo.png" style="height: 87upx;widht:87upx;margin-top: 10upx;margin-right: 10upx;"></image>
									<div>
										<div v-if="item.receiveaccount='null'" class="redusername" style="margin-top:5upx">{{item.rpk}}</div>
										<div v-else class="redusername" style="margin-top:5upx">{{item.receiveaccount}}</div>
										<div v-if="item.status==2" class="redusername" style="color:rgba(20, 20, 38, 0.5);font-size:26upx">未领取</div>
										<div v-else class="redusername" style="color:rgba(20, 20, 38, 0.5);font-size:26upx">已领取</div>
									</div>
								</div>
								<div class="reduseramount"> <span style="font-size: 34upx;font-weight: 600 ;margin-right: 4upx;">{{item.amount}}</span>
									{{item.assetname}}</div>
							</div>
						</div>
					</div>
				</div>
			</view>
		</view>
	</view>
</template>

<script>
	import account from '../../common/account.js'
	import * as oex from 'oex-web3';
	import payment from '../../common/payment.js'
	import password from '../../components/password/password.vue'
	import CryptoJS from 'crypto-js';
	export default {
		computed: {
			i18n() {
				return this.$t('user')
			}
		},
		components: {},

		data() {
			return {
				sender: "",
				mobile: "",
				phone: "",
				RedEnvelopeList: [],
				//蒙层显示
				mcxs: "display:none",
				txhash: "",
				name: "",
				remaketext: "",
				amountnum: "",
				assetname: "",
				status: "",
				alllist: [],
				redlist: [],
				amounttop: '',
				assetnametop: '',
				jmaccount: ''
			}
		},
		onLoad(options) {
			uni.hideLoading()
			var _this = this
			this.sender = options.sender
			this.amounttop = options.amount
			this.assetnametop = options.assetname
			this.getUserInfo();
			if (options.redinfoid) {
				uni.request({
					url: _this.$API.appServeApi + _this.$API.reddetail + '?i18n_language=' + uni.getStorageSync('system_info'),
					method: "POST",
					header: {
						'content-type': 'application/x-www-form-urlencoded' //自定义请求头信息
					},
					data: {
						redid: options.redinfoid
					},
					success(res) {
						console.log(res.data)
						if (res.data.code == 200) {
							var arr = res.data.data
							let arr1 = arr.filter(item => { //抢成功了但是没有领取的
								return item.status == 2 || item.status == 3;
							})
							_this.alllist = res.data.data
							_this.status = arr1.length
							
							function yctext(tel){
								var tel = tel;
								
								var reg = /^(\d{3})\d{4}(\d{4})$/;
								
								tel = tel.replace(reg, "$1****$2");
								return tel
							}
							function regEmail(email) {
							　　if (String(email).indexOf('@') > 0) {
							　　　　var str = email.split('@'),
							　　　　　　_s = '';
							　　　　if (str[0].length > 3) {
							　　　　　　for (var i = 0; i < str[0].length - 3; i++) {
							　　　　　　　　_s += '*';
							　　　　　　}
							　　　　}
							　　　　var new_email = str[0].substr(0, 3) + _s + '@' + str[1]
							　　}
							　　return new_email
							}
							for(var i=0;i<arr1.length;i++){		
								if(arr1[i].rpk.indexOf('@')==-1){
												arr1[i].rpk=yctext(arr1[i].rpk)
								}else{
												arr1[i].rpk=regEmail(arr1[i].rpk)
								}
							}
							_this.redlist = arr1
						} else {
							// _this.$CommonJS.showToast(res.data.message)
						}
					},
					fail(e) {
						uni.hideLoading()
						_this.$CommonJS.showToast(e)
					}
				})
			}
			uni.request({
				url: _this.$API.appServeApi + _this.$API.getRedGiftDetail + '?i18n_language=' + uni.getStorageSync('system_info'), //查看红包详情
				method: "POST",
				header: {
					'content-type': 'application/x-www-form-urlencoded' //自定义请求头信息
				},
				data: {
					redid: options.redinfoid
					// redid: "VlRt/s9Yx1duNd81byXQXw=="
				},
				success(res) {
					if (res.data.code == 200&res.data.data.length>0) {
						console.log(res)
						_this.name = res.data.data.sender
						_this.remaketext = res.data.data.remake
					} else {
						// _this.$CommonJS.showToast(res.data.message)
					}
				},
				fail(e) {
					uni.hideLoading()
					_this.$CommonJS.showToast(e)
				}
			})
		},
		methods: {
			async accountInfo() {
				const _this = this;
				await account.getAccount().then(res => {
					_this.accountInfomation = res.data.result;
					_this.accountName = res.data.result.accountName;
					_this.accountID = res.data.result.accountID;
					_this.yqmname = res.data.result.invitationcode
					uni.setStorage({
						key: "accountName",
						data: res.data.result.accountName
					})

				}).catch(error => {})
				this.getUserInfo(_this.accountName)
			},
			getUserInfo() {
				//获取手机号
				const _this = this;
				const data = {
					account: _this.sender
				};
				//对称验证
				var key = CryptoJS.enc.Utf8.parse("QWERTYHUJKOLL34C");
				var srcs = CryptoJS.enc.Utf8.parse(_this.sender);
				var encrypted = CryptoJS.AES.encrypt(srcs, key, {
					mode: CryptoJS.mode.ECB,
					padding: CryptoJS.pad.Pkcs7
				});
				_this.jmaccount = encrypted.toString()
				account.getuserInfo(data).then(res => {
					if (res.code == 200) {
						_this.phone = res.data.mobile;
						var data = res.data.mobile
						console.log(data)
						uni.request({
							url: _this.$API.appServeApi + _this.$API.mobile + '?i18n_language=' + uni.getStorageSync('system_info'),
							data: {
								account: _this.jmaccount
							},
							success(res) {
								if (res.data.code == 200) {
									uni.request({
										url: _this.$API.appServeApi + _this.$API.getmyredgift + '?i18n_language=' + uni.getStorageSync('system_info'),
										method: "POST",
										header: {
											'content-type': 'application/x-www-form-urlencoded'
										},
										data: {
											pk: _this.jmaccount
										},
										success(res) {
											if (res.data.code == 200 && res.data.data.length > 0) {
												_this.RedEnvelopeList = res.data.data
											} else {}
										},
										fail(e) {
											uni.hideLoading()
											_this.$CommonJS.showToast(e)
										}
									})


								} else {

								}
							}
						})

					} else {}
				}).catch(error => {})
			},
			back() {
				this.$CommonJS.navigateBack()
			},
			open(e) {
				var _this = this
				this.mcxs = "display:block"
				_this.hongbaoindex = e
			},
			mcgreyClick() {
				var _this = this
				this.mcxs = "display:none"
			},
			//领取红包
			closehongbao() {
				var _this = this
				var redinfoid = _this.RedEnvelopeList[_this.hongbaoindex].txhash
				uni.request({
					url: this.$API.appServeApi + this.$API.getAmount + '?i18n_language=' + uni.getStorageSync('system_info'),
					method: "POST",
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						pk: _this.phone,
						redinfoid: redinfoid,
						account: _this.sender
					},
					success(res) {
						if (res.data.code == 200) {
							if (_this.phone) {
								uni.request({
									url: _this.$API.appServeApi + _this.$API.getmyredgift + '?i18n_language=' + uni.getStorageSync('system_info'),
									method: "POST",
									header: {
										'content-type': 'application/x-www-form-urlencoded'
									},
									data: {
										pk: _this.jmaccount
									},
									success(res) {
										if (res.data.code == 200) {
											_this.RedEnvelopeList = res.data.data
											_this.$CommonJS.navigateTo('../red_detail/red_detail')
										} else {}
									},
									fail(e) {
										uni.hideLoading()
										_this.$CommonJS.showToast(e)
									}
								})
							}
						} else {}
					},
					fail(e) {
						uni.hideLoading()
						_this.$CommonJS.showToast(e)
					}
				})
			}
		}
	}
</script>

<style lang="stylus">
	@import "../../static/stylus/reddetail/reddetail.stylus"
</style>
